<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="供应商名称" prop="supplierName">
        <el-input
          v-model="queryParams.supplierName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商类别id" prop="supplierCategoryId">
        <el-input
          v-model="queryParams.supplierCategoryId"
          placeholder="请输入供应商类别id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主营产品或服务类别id" prop="mainProductCategoryId">
        <el-input
          v-model="queryParams.mainProductCategoryId"
          placeholder="请输入主营产品或服务类别id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结算方式" prop="settlementMethod">
        <el-input
          v-model="queryParams.settlementMethod"
          placeholder="请输入结算方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐人姓名" prop="recommenderName">
        <el-input
          v-model="queryParams.recommenderName"
          placeholder="请输入推荐人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商准入状态" prop="admissionStatus">
        <el-select v-model="queryParams.admissionStatus" placeholder="请选择供应商准入状态" clearable>
          <el-option
            v-for="dict in dict.type.gys_zr_zt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="供应商类型，企业或个人" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择供应商类型，企业或个人" clearable>
          <el-option
            v-for="dict in dict.type.gys_lb"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['supplier:gys_lr:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['supplier:gys_lr:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['supplier:gys_lr:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['supplier:gys_lr:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-more"
          size="mini"
          :disabled="single"
          @click="handleMore"
          v-hasPermi="['supplier:gys_lr:export']"
        >供应商信息详情
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gys_lrList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="供应商唯一ID" align="center" prop="id" />-->
      <el-table-column label="供应商名称" align="center" prop="supplierName"/>
      <el-table-column label="供应商类别id" align="center" prop="supplierCategoryId"/>
      <el-table-column label="主营产品或服务类别id" align="center" prop="mainProductCategoryId"/>
      <el-table-column label="供应商详细地址" align="center" prop="detailedAddress"/>
      <el-table-column label="开户银行名称" align="center" prop="bankName"/>
      <el-table-column label="银行账户" align="center" prop="bankAccount"/>
      <el-table-column label="结算方式" align="center" prop="settlementMethod"/>
      <el-table-column label="保证金金额" align="center" prop="deposit"/>
      <el-table-column label="推荐人姓名" align="center" prop="recommenderName"/>
      <el-table-column label="推荐人联系电话" align="center" prop="recommenderPhone"/>
      <el-table-column label="供应商准入状态" align="center" prop="admissionStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.gys_zr_zt" :value="scope.row.admissionStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="供应商类型，企业或个人" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.gys_lb" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['supplier:gys_lr:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['supplier:gys_lr:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改供应商信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="供应商名称" prop="supplierName">
          <el-input v-model="form.supplierName" placeholder="请输入供应商名称"/>
        </el-form-item>
        <el-form-item label="供应商类别id" prop="supplierCategoryId">
          <el-input v-model="form.supplierCategoryId" placeholder="请输入供应商类别id"/>
        </el-form-item>
        <el-form-item label="主营产品或服务类别id" prop="mainProductCategoryId">
          <el-input v-model="form.mainProductCategoryId" placeholder="请输入主营产品或服务类别id"/>
        </el-form-item>
        <el-form-item label="供应商详细地址" prop="detailedAddress">
          <el-input v-model="form.detailedAddress" placeholder="请输入供应商详细地址"/>
        </el-form-item>
        <el-form-item label="开户银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户银行名称"/>
        </el-form-item>
        <el-form-item label="银行账户" prop="bankAccount">
          <el-input v-model="form.bankAccount" placeholder="请输入银行账户"/>
        </el-form-item>
        <el-form-item label="结算方式" prop="settlementMethod">
          <el-input v-model="form.settlementMethod" placeholder="请输入结算方式"/>
        </el-form-item>
        <el-form-item label="保证金金额" prop="deposit">
          <el-input v-model="form.deposit" placeholder="请输入保证金金额"/>
        </el-form-item>
        <el-form-item label="推荐人姓名" prop="recommenderName">
          <el-input v-model="form.recommenderName" placeholder="请输入推荐人姓名"/>
        </el-form-item>
        <el-form-item label="推荐人联系电话" prop="recommenderPhone">
          <el-input v-model="form.recommenderPhone" placeholder="请输入推荐人联系电话"/>
        </el-form-item>
        <el-form-item label="供应商准入状态" prop="admissionStatus">
          <el-select v-model="form.admissionStatus" placeholder="请选择供应商准入状态">
            <el-option
              v-for="dict in dict.type.gys_zr_zt"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="供应商类型，企业或个人" prop="type">
          <el-select v-model="form.type" placeholder="请选择供应商类型，企业或个人">
            <el-option
              v-for="dict in dict.type.gys_lb"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listGys_lr, getGys_lr, delGys_lr, addGys_lr, updateGys_lr} from "@/api/supplier/gys_lr";

export default {
  name: "Gys_lr",
  dicts: ['gys_lb', 'gys_zr_zt'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商信息表格数据
      gys_lrList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierName: null,
        supplierCategoryId: null,
        mainProductCategoryId: null,
        settlementMethod: null,
        recommenderName: null,
        admissionStatus: null,
        type: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        supplierName: [
          {required: true, message: "供应商名称不能为空", trigger: "blur"}
        ],
        supplierCategoryId: [
          {required: true, message: "供应商类别id不能为空", trigger: "blur"}
        ],
        mainProductCategoryId: [
          {required: true, message: "主营产品或服务类别id不能为空", trigger: "blur"}
        ],
        detailedAddress: [
          {required: true, message: "供应商详细地址不能为空", trigger: "blur"}
        ],
        settlementMethod: [
          {required: true, message: "结算方式不能为空", trigger: "blur"}
        ],
        deposit: [
          {required: true, message: "保证金金额不能为空", trigger: "blur"}
        ],
        recommenderName: [
          {required: true, message: "推荐人姓名不能为空", trigger: "blur"}
        ],
        recommenderPhone: [
          {required: true, message: "推荐人联系电话不能为空", trigger: "blur"}
        ],
        admissionStatus: [
          {required: true, message: "供应商准入状态不能为空", trigger: "change"}
        ],
        type: [
          {required: true, message: "供应商类型，企业或个人不能为空", trigger: "change"}
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询供应商信息列表 */
    getList() {
      this.loading = true;
      listGys_lr(this.queryParams).then(response => {
        this.gys_lrList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        supplierName: null,
        supplierCategoryId: null,
        mainProductCategoryId: null,
        detailedAddress: null,
        bankName: null,
        bankAccount: null,
        settlementMethod: null,
        deposit: null,
        recommenderName: null,
        recommenderPhone: null,
        admissionStatus: null,
        type: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加供应商信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGys_lr(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改供应商信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGys_lr(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGys_lr(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除供应商信息编号为"' + ids + '"的数据项？').then(function () {
        return delGys_lr(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('supplier/gys_lr/export', {
        ...this.queryParams
      }, `gys_lr_${new Date().getTime()}.xlsx`)
    },
    handleMore(row) {
      // 获取待查看列的id
      const id = row.id || this.ids[0]

      // 跳转到对应的页面


    }
  }
};
</script>
